package com.googlecode.lohr.parser.combinators.matcher;

import com.googlecode.lohr.parser.combinators.MatchError;
import com.googlecode.lohr.parser.combinators.node.AbstractNode;

abstract public class MatchTask implements MatchListener {
	
	protected Matcher currentMatcher;
	protected MatchContext ctx;
	protected int start;
	public MatchTask(MatchContext ctx, Matcher matcher, int start) {
		currentMatcher= matcher;
		this.ctx= ctx;
		this.start= start;
	}

	@Override
	public void onMatchFound(AbstractNode match) {
		// do nothing
	}

	@Override
	public void onMatchComplete(MatchError matchError) {
		// do nothing
	}
	
	public void stopMatching() {
		ctx.matchComplete(currentMatcher, start);
	}
	
	public void run() {
		ctx.doMatch(currentMatcher, start, this);
	}

}
